home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / ip / dns / ddt2.0 / cmd / nets < prev    next >
Encoding:
Text File  |  1993-05-17  |  1.6 KB  |  49 lines

  1. #! /usr/local/bin/perl
  2. #
  3. #  nets - counts the number of hosts per net. The last input column should 
  4. #      be an IP address (see hosts-addr)
  5. #
  6. #               The names should be absolute (see expand)
  7. #
  8. #  Copyright (C) 1992, 1993 PUUG - Grupo Portugues de Utilizadores
  9. #                                  do Sistema UNIX
  10. #                1992, 1993 FCCN - Fundacao para o Desenvolvimento dos Meios 
  11. #                                  Nacionais de Calculo Cientifico 
  12. #
  13. #  Authors: Jorge Frazao de Oliveira <frazao@puug.pt>
  14. #           Artur Romao <artur@dns.pt>
  15. #
  16. #  This file is part of the DDT package, Version 2.0.
  17. #
  18. #  Permission to use, copy, modify, and distribute this software and its 
  19. #  documentation for any purpose and without any fee is hereby granted, 
  20. #  provided that the above copyright notice appear in all copies.  Neither 
  21. #  PUUG nor FCCN make any representations about the suitability of this
  22. #  software for any purpose.  It is provided "as is" without express or 
  23. #  implied warranty.
  24.  
  25. $[ = 1;            # set array base to 1
  26.  
  27. while (<STDIN>) {
  28.         chop;    # strip record separator
  29.         @Field = split(' ', $_);
  30.  
  31.         @address = split(/\./, $Field[$#Field]);
  32.  
  33.     # build the net number, according to its class
  34.         if (($address[1] >= 1) && ($address[1] < 127)) {    # class A
  35.         $net{join(".", $address[1], "0.0.0")}++;
  36.         }
  37.     elsif (($address[1] >= 128) && ($address[1] < 192)) {    # class B
  38.         $net{join(".", $address[1], $address[2], "0.0")}++;
  39.         }
  40.     elsif (($address[1] >= 192) && ($address[1] < 224)) {    # class C
  41.         $net{join(".", $address[1], $address[2], $address[3], "0")}++;
  42.         }
  43. }
  44.  
  45. foreach $n (keys %net) {
  46.         printf "%5d %s\n", $net{$n}, $n;
  47. }
  48.  
  49.